<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *页面管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['basicname']){
	$_SESSION['plugin_name']=$_RQ['basicname'];
}
$_SESSION['plugin_name'] = $_SESSION['plugin_name'] ? $_SESSION['plugin_name'] :'core';
if($_SESSION['plugin_name'] && $_SESSION['plugin_name'] !='core'){
	if (method_exists($this->plugin($_SESSION['plugin_name']),'getplugins')){
		$getplugins = $this->plugin($_SESSION['plugin_name'])->getplugins();
	}
}
$return['webtypes']=array(
	'0'=>'自定义页面',
	'1'=>'系统页面',
	'2'=>'插件页面',
);
$return['syspages']=get_sys_diypages();
$plugins =array();
if($getplugins){
	foreach($getplugins as &$type){
			foreach($type['list'] as $k=>&$p){
				if($p['is_install']){
					$plugins[]=$p;
				}else{
					unset($type['list'][$k]);
				}
			}
	}
}
/*if(empty($_SESSION['actiontypes'])){
	$types =array();
	$plugins = pdo_getall('core_plugins',array(),array('name','title'));
	foreach($plugins as $p){
		$isdiy = pdo_getall('core_mobile_blocks',array('type'=>1,'plugin_id'=>$p['name']));
		$install = check_permission($p['name']);
		if(!empty($isdiy) && $install){
			$actiontypes = $this->plugin($p['name'])->getactiontypes();
				foreach($actiontypes as $u=>$t){
					$types[$p['name'].'/'.$u]=$p['title'].'-'.$t;
				}
		}
	}
	$_SESSION['actiontypes'] = $types;
}*/
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'webid'=>0,'pctype'=>array(0,1));
	if($_SESSION['plugin_name']){
		//$params['plugin_name']=$_SESSION['plugin_name'];
	}
	if($_RQ['pageaction']){
		$params['pageaction']=trim($_RQ['pageaction']);
		$return['params']['pageaction']=$_RQ['pageaction'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['plugin_name'])){
		$params['plugin_name']=trim($_RQ['plugin_name']);
		$return['params']['plugin_name']=$_RQ['plugin_name'];
	}
	if(!empty($_RQ['webtype'])){
		$params['webtype']=trim($_RQ['webtype']);
		$return['params']['webtype']=$_RQ['webtype'];
	}
	$orderby='star desc,id desc';
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','star','webtype','title','createtime','status','html','pageaction','plugin_name');
	$list=pdo_getslice('core_mobile_web',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	if($list){
		foreach($list as &$item){
			$item['preview']=custom_url('core/welcome//id='.$item['id'],true);
			if($item['plugin_name'] && $item['pageaction']){
				$item['url']=custom_url($item['plugin_name'].'/'.$item['pageaction'].'/',true);
				if($item['plugin_name']!='core'){
					$plugininfo=pdo_get('core_plugins',array('name'=>$item['plugin_name']),array('title','diypage'));
					$item['pageaction'] = $item['pageaction'] ? $item['pageaction'] :'无';
					$diypage = $plugininfo['diypage']?: '[{"action":"index","title":"首页"}]';
					if($diypage){
						$diypage = json_decode($diypage,true);
						foreach($diypage as $diy){
							if($diy['action']==$item['pageaction']){
								$item['pageaction'] = $diy['title'];
							}
						}
					}
				}else{
					foreach($return['syspages'] as $diy){
							if($diy['url']==$item['pageaction']){
								$item['pageaction'] = $diy['title'];
							}
					}
				}
			}else{
				$item['url']=custom_url('core/welcome//id='.$item['id'],true);
			}
			if($item['webtype']==1){
					foreach($return['syspages'] as $diy){
							if($diy['url']==$item['pageaction']){
								$item['pageaction'] = $diy['title'];
							}
					}
			}
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('action'=>'jy_diypage/index/list/','title'=>'页面列表'),
			array('action'=>'jy_diypage/index/edit/','title'=>'添加页面'),
			array('action'=>'jy_diypage/diypage_template/my/','title'=>'我的模板'),
		),
		'list'=>array('data'=>'list','tip'=>'【温馨提示】:</br><red>为了避免场景关联性页面的困惑，下面列出所有插件的装修页面,请按需设置，也可搜索查询！</red>','list'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'star','title'=>'星数','type'=>'star','set'=>'star'),
			array('name'=>'webtype','title'=>'页面类型','type'=>'radio','options'=>'webtypes'),
			array('name'=>'plugin_name','title'=>'所属插件','type'=>'select','options'=>'plugins'),
			array('name'=>'pageaction','title'=>'关联页面','type'=>'string'),
			array('name'=>'status','title'=>'启用/关闭','type'=>'switch','set'=>'set'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
			array('name'=>'preview','title'=>'预览二维码','type'=>'ewm'),
			array('name'=>'preview','title'=>'预览链接','type'=>'copy'),
			array('action'=>'jy_diypage/mobile_web_tpls//','title'=>'DIY布局','type'=>'href'),
			array('name'=>'url','title'=>'复制链接(启用后有效)','type'=>'copy'),
		),'batch'=>array(
			array('type'=>'post','url'=>'jy_diypage/index/update/','title'=>'一键更新页面类型（仅限首次页面类型不对称时）'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'type'=>'string','title'=>'页面名称'),
			array('name'=>'webtype','width'=>15,'type'=>'radio','options'=>'webtypes','title'=>'页面类型'),
			array('type'=>'choose','width'=>13,'title'=>'所属插件','name'=>'plugin_name','action'=>'core/basic.get_plugins/'),
		)
	);
	$return['plugins']=pdo_getall('core_plugins',array('type'=>3),array('name','title'),'name');
	$return['plugins']['core']=array('name'=>'core','title'=>'系统页面');
	$return['htmls']=$htmls;
	set_html('title','页面装修');
	exi($return);
}
if($_RQ['op']=='edit'){
	//编辑页面，添加页面在页面模版列表那边选择模版然后添加
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('core_mobile_web',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']),array('id','webtype','title','status','nopc','openlogin','domain','foot','wxapp_id','menu_id','syscolor','plugin_name','pageaction'));	
	}else{
		$item=array();
	}
	if($item['wxapp_id']){
		$item['wxapp_type']=1;
	}else{
		$item['wxapp_type']=3;
	}
	$params=array('id'=>$id);
	if($_SESSION['plugin_name']){
		$params['plugin']=$_SESSION['plugin_name'];
		$params['action']=$item['pageaction'];
	}else{
		$params['plugin']='core';
		$params['action']='welcome';
	}
	$params['key']='web'.$id;
	$back=cfc('core')->get_back_newss($params);
	$item=array_merge($back,$item);
	$return['item']=$item;	
	$default=array(
		
	);
	$return['wxapp_types']=array(
		'1'=>'关联已有小程序',
		'2'=>'创建同名小程序并关联',
		'3'=>'不关联小程序',
	);
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'设置页面信息',
		'tabs'=>array(
			array('op'=>'list','title'=>'页面列表'),
		),
		'edit'=>array(
						array('type'=>'string','name'=>'title','title'=>'页面名称','must'=>true),
						cfc('core')->keywords(),
						array('name'=>'webtype','title'=>'页面类型','type'=>'radio','options'=>'webtypes'),
						array('type'=>'select','name'=>'pageaction','title'=>'系统页面','options'=>'syspages','option_value'=>'url','show'=>array('webtype'=>1)),
						array('type'=>'select_more','name'=>'plugin_name','title'=>'选择页面插件','options'=>'plugins','option_value'=>'name','show'=>array('webtype'=>2),'help'=>'选择本页面所属的插件！'),
						array('type'=>'select','name'=>'pageaction','title'=>'选择页面','options'=>'plugins[pagedata.item.plugin_name].pages','option_value'=>'action','show'=>array('webtype'=>2),'help'=>'选择要DIY的页面，只有该页面启用后，客户访问该页面的时候，将展示DIY的效果！'),
						array('type'=>'image','name'=>'picurl','title'=>'封面图片'),
						array('type'=>'switch','name'=>'status','title'=>'是否启用'),
						array('type'=>'switch','name'=>'nopc','title'=>'是否关闭PC页面','help'=>'关闭PC页面后，PC端将只访问微官网页面'),
						array('type'=>'switch','name'=>'openlogin','title'=>'是否启用登录','help'=>'开启后，访问页面，会检查会员登录，方便获取客户信息，绑定上下级关系等'),
						array('type'=>'tip','title'=>'【<red>温馨提示</red>】：本配色只能实用于页面本身或关联的小程序；要其他全局页面配色生效，需移步：站点设置-》基本信息-》界面UI配色'),
						array('type'=>'color_pool','name'=>'syscolor','title'=>'选择配色方案','help'=>''),
						array('type'=>'colorpicker','name'=>'syscolor','title'=>'微官网主题色','help'=>''),
						array('type'=>'phone_tpl','name'=>'syscolor','demo'=>1,'title'=>'演示效果'),
						array('type'=>'text','name'=>'description','title'=>'页面描述'),
						array('type'=>'string','name'=>'domain','title'=>'绑定域名'),
						array('type'=>'text','name'=>'foot','title'=>'底部自定义'),
						array('type'=>'select','name'=>'menu_id','title'=>'自定义底部菜单','options'=>'menus'),
						//array('type'=>'radio','name'=>'wxapp_type','title'=>'关联小程序设置','options'=>'wxapp_types','关联小程序后，设计微官网的同时，系统会自动将您的设计应用在关联小程序中'),
						//array('type'=>'select','name'=>'wxapp_id','title'=>'选择要关联的小程序','options'=>'wxapps','show'=>array('wxapp_type',1)),
		)
	);
	$plugins=pdo_getall('core_plugins',array('type'=>3,'style <>'=>6),array('name','title'),'name','star desc, is_legao desc');
	foreach($plugins as $k=>&$p){
			$install = check_permission($p['name']);
			if(!$install){
				continue;
			}
			$diypage = pdo_getcolumn('core_plugins',array('name'=>$p['name']),'diypage');
			$diypage = $diypage ? $diypage : '[{"action":"index/","title":"首页"}]';
			if($diypage){
				$plugins[$p['name']]=array(
					'name'=>$p['name'],
					'title'=>$p['title'],
					'pages'=>json_decode($diypage,true),
				);
			}else{
				unset($plugins[$k]);
			}
	}
	$return['plugins']=$plugins ? $plugins : array();
	$return['htmls']=$htmls;
	$return ['menus']=pdo_getall('core_diy_menu',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['keytypes']=get_keyword_types();
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$id=intval($post['id']);
	if(!$post['keywords']){
		exi('请先设置关键词！','error');
	}
	//更新微站数据
	$post['plugin_name']=$post['webtype']==1?'core':$post['plugin_name'];
	$post['pageaction']=$post['pageaction']=='index/'?'index':$post['pageaction'];
	$updata=array_fields(array('title','nopc','openlogin','status','foot','domain','menu_id','syscolor','plugin_name','pageaction','webtype'),$post);
	if(!$id){
		//添加微站
		model('core/web')->check_num('mobile');
		$updata['uniacid']=$_SESSION['uniacid'];
		$updata['createtime']=TIMESTAMP;
		pdo_insert('core_mobile_web',$updata);
		$web_id=pdo_insertid();
	}else{
		$web_id=$id;
		pdo_update('core_mobile_web',$updata,array('id'=>$web_id,'uniacid'=>$_SESSION['uniacid']));	
		if($post['is_default']){
			//设为首页
			uni_setting('default_mobile_web',$id);
		}
	}
	//插入回复规则
	$data=array_fields(array('title','status','description','picurl','keywords'),$post);
	$data['plugin']=$post['plugin_name']?$post['plugin_name']:'core';
	$data['action']=$post['plugin_name']?$post['pageaction']:'welcome';
	$data['id']=$web_id;
	$data['key']='web'.$web_id;
	cfc('core')->save_back_news($data);
	$check=pdo_getcolumn('core_account_wxapp',array('web_id'=>$web_id),'id');
	if(!$check){
			$insert=pdo_get('core_mobile_web',array('id'=>$web_id,'uniacid'=>$_SESSION['uniacid']),array('items','setting'));
			$insert['uniacid']=$_SESSION['uniacid'];
			$insert['type']=1;
			$insert['web_id']=$web_id;
			$insert['createtime']=time();
			$insert['title']=$data['title'];
			$insert['syscolor']=$data['syscolor'];
			pdo_insert('core_account_wxapp',$insert);
			$wxapp_id=pdo_insertid();
			pdo_update('core_mobile_web',array('wxapp_id'=>$wxapp_id),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));	
	}
	exi('保存成功！','','list');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的页面！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		$item=pdo_get('core_mobile_web',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		if(intval($post['status'])==1){
			$isset=pdo_getcolumn('core_mobile_web',array('status'=>1,'plugin_name'=>$item['plugin_name'],'pageaction'=>$item['pageaction'],'uniacid'=>$_SESSION['uniacid']),'id');
			if($isset){
				exi('同一页面类型只能开启一个！','error','list');
			}
		}
		pdo_update('core_mobile_web',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	if(isset($post['is_default'])){
		$default=intval($post['is_default']);
		if($default){
			$default=$id;
		}
		uni_setting('default_mobile_web',$default);
	}
	exi('操作成功！');
}
if($_RQ['op']=='uptpl'){
	$tpl_id=intval($_RQ['id']);
	if(!$tpl_id){
			exi('请先选择要的模板！','error');
	}
	$temid=pdo_getcolumn('core_mobile_template',array('tpl_id'=>$tpl_id),'id');
	if($temid){
		$data=pdo_get('core_account_web_tpl',array('id'=>$tpl_id,'uniacid'=>$_SESSION['uniacid']),array('items','setting','pageaction','plugin_name'));
		$pages=pdo_getall('core_account_web_tpl',array('tpl_id'=>$tpl_id,'uniacid'=>$_SESSION['uniacid']),array('title','items','setting','pageaction','plugin_name'));
		$insert=array(
			'items'=>$data['items'],
			'setting'=>$data['setting'],
			'pageaction'=>$data['pageaction'],
			'plugin_name'=>$data['plugin_name'],
			'pages'=>ijson_encode($pages),
		);
		pdo_update('core_mobile_template',$insert,array('id'=>$temid,'uniacid'=>$_SESSION['uniacid']));
		exi('同步模版成功！');
	}else{
		exi('','','/website.mobile_web/release/id='.$tpl_id);
	}
}
if($_RQ['op']=='release'){
	//发布到模版市场，发布到模版市场是否需要设置价格和分类？暂时先不发布，直接保存为我的模版
	if($_RQ['postdata']){
		$post=get_postdata();
		$tpl_id=intval($post['tpl_id']);
		if(!$tpl_id){
			exi('请先选择页面！','error');
		}
		$data=pdo_get('core_account_web_tpl',array('id'=>$tpl_id,'uniacid'=>$_SESSION['uniacid']),array('items','setting','pageaction','plugin_name'));
		$pages=pdo_getall('core_account_web_tpl',array('tpl_id'=>$tpl_id,'uniacid'=>$_SESSION['uniacid']),array('title','items','setting','pageaction','plugin_name'));
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'type'=>intval($post['type']),
			'title'=>$post['title'],
			'image'=>$post['image'],
			'items'=>$data['items'],
			'setting'=>$data['setting'],
			'pageaction'=>$data['pageaction'],
			'plugin_name'=>$data['plugin_name'],
			'pages'=>ijson_encode($pages),
			'tpl_id'=>$tpl_id,
		);
		pdo_insert('core_mobile_template',$insert);
		exi('保存模版成功！','','list');
	}else{
		$id=intval($_RQ['id']);
		if(!$id){
			exi('请先选择要的模板！','error');
		}
		$return['item']=pdo_get('core_mobile_template',array('tpl_id'=>$id),array('id','tpl_id','title','image','type'));
		$return['item']=$return['item']?:array('tpl_id'=>$id);
		$return['types']=pdo_getall('core_template_group',array(),array('id','title'));
		$return['htmls']=array(
			'type'=>'edit',
			'desc'=>'设置模版信息',
			'edit'=>array(
				array('type'=>'string','name'=>'title','title'=>'模版名称'),
				array('type'=>'select','name'=>'type','title'=>'模版类型','options'=>'types'),
				array('type'=>'image','name'=>'image','title'=>'模版图片','help'=>'上传一张图片展示模版效果'),
			),
		);
		exi($return);
	}
}
if($_RQ['op']=='release_wxapp'){
	//发布到模版市场，发布到模版市场是否需要设置价格和分类？暂时先不发布，直接保存为我的模版
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['web_id']);
		if(!$id){
			exi('请先选择微站！','error');
		}
		$data=pdo_get('core_mobile_web',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']),array('items','setting'));
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'group_id'=>intval($post['type']),
			'title'=>$post['title'],
			'image'=>$post['image'],
			'items'=>$data['items'],
			'setting'=>$data['setting'],
		);
		pdo_insert('core_wxapp_template',$insert);
		exi('保存模版成功！','','list');
	}else{
		$id=intval($_RQ['id']);
		if(!$id){
			exi('请先选择要保存的微网站！','error');
		}
		$return['item']=array('web_id'=>$id);
		$return['types']=pdo_getall('core_template_group',array(),array('id','title'));
		$return['htmls']=array(
			'type'=>'edit',
			'desc'=>'设置模版信息',
			'edit'=>array(
				array('type'=>'string','name'=>'title','title'=>'模版名称'),
				array('type'=>'select','name'=>'type','title'=>'模版类型','options'=>'types'),
				array('type'=>'image','name'=>'image','title'=>'模版图片','help'=>'上传一张图片展示模版效果'),
			),
		);
		exi($return);
	}
}
if($_RQ['op']=='design'){
	//页面设计
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$id){
			exi('请先选择页面！','error');
		}
		if($post['items']){
			foreach($post['items'] as &$v){
				if($v['extradata']){
					unset($v['extradata']);
				}
			}
		}
		$update=array(
			'items'=>$post['items']?ijson_encode($post['items']):'',
			'setting'=>$post['setting']?ijson_encode($post['setting']):''
		);
		if($update['items'] || $update['setting']){
			//检测恶意代码
			if(strexists($update['items'],'<?') || strexists($update['setting'],'<?')){
				exi('提交内容存在恶意代码，无法提交！','error');
			}
			if($post['type']!='template'){//type==template表示设计的是模版，设计模版时无需生成具体页面
				//获取开发者自己的组件，并上传
				$local_blocks=pdo_getall('core_mobile_blocks',array('madehtml <>'=>''),array('cloud_id','default','madehtml'),'cloud_id');
				if($local_blocks){
					foreach($local_blocks as &$row){
						$row['madehtml']=cfc('files')->source_read($row['madehtml']);
						$row['default']=$row['default']?json_decode($row['default'],true):array();
					}
				}
				//设计完成后，对接云端生成页面
				$post=array('items'=>base64_encode($update['items']),'setting'=>base64_encode($update['setting']),'local_blocks'=>$local_blocks);
				$html=cloud_request('diy.mobile.made',$post);
				//将获得生成的html代码存入文件
				$item=pdo_get('core_account_web_tpl',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']),array('html'));
				$html=cfc('files')->source_save($html,'page','html','微站页面：'.$id,$item['html']);
				if(!$item['html']){
					$update['html']=$html;
				}
			}
		}
		if($post['type']=='template'){
			pdo_update('core_mobile_template',$update,array('id'=>$id));
			exi('保存模板成功！','','goback');
		}
		$update['updatetime']=TIMESTAMP;
		pdo_update('core_account_web_tpl',$update,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('保存成功！','','goback');
	}else{
		$id=intval($_RQ['id']);
		$art_num=intval($_RQ['art_num']);
		$fenlei_num=intval($_RQ['fenlei_num']);
		$store_num=intval($_RQ['store_num']);
		if(!$id){
			exi('请先选择要设计的页面！','error');
		}
		if($_SESSION['os']!='windows'){
			exi('请在PC端设计微网站！','error','list');
		}
		$return['used_navs']=array();
		if($_RQ['type']=='template'){
			$item=pdo_get('core_mobile_template',array('id'=>$id),array('id','title','items','setting'));
			$item['type']='template';
		}else{
			$item=pdo_get('core_account_web_tpl',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']),array('id','tpl_id','web_id','title','items','setting'));
			//$_SESSION['mobile_web']['group_id']=$item['group_id'];
			if($item['web_id']){
				$_SESSION['mobile_web']['webid']=$item['webid'];
				if($item['tpl_id']==0){
					$_SESSION['mobile_web']['mod_id']=$id;
				}else{
					$_SESSION['mobile_web']['mod_id']=$item['tpl_id'];
				}
			}else{
				$_SESSION['mobile_web']['webid']=$id;
			}
		}
		$item['items']=$item['items']?json_decode($item['items'],true):array();
		if($item['items']){
			foreach($item['items'] as $row){
				if(!$return['used_navs'][$row['nid']]){
					$return['used_navs'][$row['nid']]=pdo_get('core_mobile_blocks',array('cloud_id'=>$row['nid']),array('name','showhtml','edithtml'));
				}
			}
		}
		$item['setting']=$item['setting']?json_decode($item['setting'],true):array('guide'=>array('title1'=>''));
		$navs0=pdo_getall('core_mobile_blocks',array('type'=>0,'basictype'=>0,'support <>'=>2),array(),'','usenum desc',array('10'));
		if($navs0){
			foreach($navs0 as &$nav){
				$nav['default']=json_decode($nav['default'],true);
			}
		}
		$navs1=pdo_getall('core_mobile_blocks',array('type'=>0,'basictype'=>1,'support <>'=>2),array(),'','usenum desc',array('10'));
		if($navs1){
			foreach($navs1 as &$nav){
				$nav['default']=json_decode($nav['default'],true);
			}
		}
		
		// 应用组件
		$pluginparams = array('type'=>1,'support <>'=>2);
		$plugins = $this->plugins($_SESSION['plugin_name']);
		
		if(!empty($plugins)){
			$pluginparams['plugin_id']=$plugins;
			$navs2=pdo_getall('core_mobile_blocks',$pluginparams,array(),'','usenum desc',array('10'));
			if($navs2){
				$plugintitles=array();
				$plugins=array();
				$i = 0;
				foreach($navs2 as $k=>&$nav){
					$plugintitle=pdo_getcolumn('core_plugins',array('name'=>$nav['plugin_id']),'title');
					$nav['default']=json_decode($nav['default'],true);
				if (!$plugintitle || in_array($plugintitle,$plugintitles)){
						
					}else{
						$plugintitles[$i] = $plugintitle;
						$plugins[$i]['name'] = $nav['plugin_id'];
						$plugins[$i]['plugintitle']=$plugintitle;
						$blocks = pdo_getall('core_mobile_blocks',array('type'=>1,'plugin_id'=>$nav['plugin_id']),array(),'','usenum desc',array('10'));
						foreach($blocks as &$b){
							$b['default']=json_decode($b['default'],true);
						}
						$plugins[$i]['navs'] = $blocks;
						$i  += 1;
					}
					
				}
			}
		}
		
		$return['navs0']=$navs0;
		$return['navs1']=$navs1;
		$return['navs2']=$plugins;
		$return['edit']=3;
		$item['setting']['bg']=!empty($item['setting']['bg'])?$item['setting']['bg']:array('bg'=>'');
		$item['setting']['top']['title']=$item['setting']['top']['title']?$item['setting']['top']['title']:$item['title'];
		$return['menus']=pdo_getcolumn('core_diy_menu',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>'core','status'=>1),'data');
		$return['menus']=json_decode($return['menus'],true);
		$item['setting']['footer']['menus']=!empty($item['setting']['footer']['menus']) ? $item['setting']['footer']['menus']:$return['menus']['menus'];
		$item['setting']['footer']['chosecolor']=$item['setting']['footer']['chosecolor']?:$_SESSION['customsyscolor'];
		$return['fenleis']=pdo_getall('core_account_article_fenlei',array('uniacid'=>$_SESSION['uniacid']));
		$return['articles']=pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid']));
		$return['store_group']=pdo_getall('core_account_store_group',array('uniacid'=>$_SESSION['uniacid']));
		$return['article_store']=pdo_getall('core_account_store',array('uniacid'=>$_SESSION['uniacid']));
		$return['account']=$_SESSION['account'];
		$return['item']=$item;
		$return['extradata']=array();
		exi($return);
	}
}
if($_RQ['op']=='link'){
	$list=pdo_getall('core_account_web_tpl',array('tpl_id'=>$_SESSION['mobile_web']['mod_id'],),array('id','title','tpl_id'));
	$list[]=array('title'=>'首页','id'=>$_SESSION['mobile_web']['mod_id']);
	if($list){
		foreach($list as &$item){
			$item['url']='core/welcome/main/pageid='.$item['id'];
		}
	}
	if($_RQ['from']=='action'){
		$query='from=action';
	}else{
		$query='';
	}
	$return['list']=$list;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'link','title'=>'站内页面'),
			array('plugin'=>$_SESSION['plugin_name']?$_SESSION['plugin_name']:'jy_weishop','action'=>'link','title'=>'本应用功能页'),
			array('plugin'=>'core','action'=>'tools.link','query'=>$query,'title'=>'系统其他页面'),
		),
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	exi($return);
}
if($_RQ['op']=='getnav'){
	$params=array();
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
	}
	$navs=pdo_getall('core_mobile_blocks',$params,array(),'','usenum desc',array('10'));
	exi($navs);
}
if($_RQ['op']=='star'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['star'])){
		$update['star']=$post['star'];
	}
	if($update){
		pdo_update('core_mobile_web',$update,array('id'=>$id));
	}
	exi('操作成功！');
}
if($_RQ['op']=='update'){
	$list=pdo_getall('core_mobile_web',array('webtype'=>0,'plugin_name <>'=>'','uniacid'=>$_SESSION['uniacid']));
	foreach($list as $item){
		if($item['plugin_name']!='core'){
			pdo_update('core_mobile_web',array('webtype'=>2),array('id'=>$item['id']));
		}
	}
	exi('操作成功！');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_mobile_web',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('core_mobile_web',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}